<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>待确认订单 - 拼多多订单 - 电商ERP系统</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;top: 0px;">
    <div class="layui-tab layui-tab-brief" lay-filter="demo">
        <ul class="layui-tab-title">
            <li ><a th:href="@{/pdd/order_list(shopId=${shopId},status=1,refundStatus=1)}">待发货</a></li>
            <!-- <li><a th:href="@{/fahuo/wait_confirm_order_list_pdd(shopId=${shopId})}">待确认</a></li> -->
            <li ><a th:href="@{/pdd/order_list(shopId=${shopId},status=2,refundStatus=1)}">已发货待签收</a></li>
            <li ><a th:href="@{/pdd/order_list(shopId=${shopId})}">全部订单</a></li>
            <li class="layui-this"><a href="/fahuo/wait_confirm_order_list_pdd">待确认订单</a></li>

     
        </ul>
    </div>
    <!-- start sp-wrapper -->
    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane1" method="get" action="/fahuo/wait_confirm_order_list_pdd">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="orderNum" th:value="${orderNum}" placeholder="订单编号" class="layui-input">
                    </div>
<!--                    <div class="layui-inline">-->
<!--                        <input type="text" name="mobile" th:value="${mobile}" placeholder="收货人手机号" class="layui-input">-->
<!--                    </div>-->
                    <div class="layui-inline">
                        <input type="text" name="pddGoodsId" th:value="${pddGoodsId}" placeholder="pddGoodsId" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">下单时间</label>
                        <div class="layui-inline">
                            <input type="text" class="layui-input" name="startTime" id="startTime" placeholder="yyyy-MM-dd" th:value="${startTime}" style="width: 120px;" autocomplete="off">
                        </div>
                        <div class="layui-inline">
                            <input type="text" class="layui-input" name="endTime" id="endTime" placeholder="yyyy-MM-dd" th:value="${endTime}" autocomplete="off" style="width: 120px;">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <select name="shopId" id="shopId">
                            <option value="0">店铺</option>
                            <option  th:each="item: ${shops}" th:text="${item.name}" th:value="${item.id}">等待发货</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">搜索</button>
                        <i>总共：&nbsp;[[${totalSize}]]&nbsp;条记录</i>
                    </div>
                    
                    <!-- <div class="layui-inline" >
                        <a class="layui-btn layui-btn-primary" href="javascript:;" id="export_order">导出结算订单</a>
                    </div> -->

                    <div class="layui-inline"></div>

                </div>
                <div class="layui-form-item" style="display: none;">
                    <div class="layui-inline">
                        <a class="layui-btn layui-btn-warm" href="javascript:;" id="confirm_batch">批量确认（<span id="order-num">0</span>）</a>
                    </div>
                </div>
            </form>



        </div>
    </fieldset>

    <link rel="stylesheet" href="/sb/stock.css"/>
    <div class="sp-wrapper">
        <div class="sp-table">
            <table>
                <thead>
                <tr>
                    <th><input id="allCheck" type="checkbox"/>ID</th>
                    <th>订单号</th>
                    <th>商品</th>
                    <th>收货人</th>
                    <th>所属店铺</th>
     
                    <th>备注</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="sp-data">
                <tr th:each="item:${list}">
                    <td >
                        <input type="checkbox" name="ids" th:value="${item.id}" th:if="${item.refund_status != 4 && item.auditStatus == 0}" class="ids currCheck" />
                        <h th:text="${item.id}"></h>
                    </td>
                    <td>
                        <p><b th:text="${item.orderSn}"></b></p>
                        <p><b style="color:#afafaf;" th:text="${item.created_time}"></b></p>
                    </td>
                    <td>
                        <div th:each="it:${item.items}">
                            <p style="float:left">
                                <img th:src="${it.goodsImg}">
                            </p>
                            <p style="float:left;padding-left: 10px;">
                                <b th:text="${#strings.abbreviate(it.goodsName,25)}" th:title="${it.goodsName}"></b>
                                <br />
                                <b th:text="${it.goodsNum}"></b>
                                <b th:text="${it.goodsSpec}"></b>
                                
                                数量：<b style="color: #e01a1a" th:text="${it.quantity}"></b>
                                <br />
                                SKU:<b th:text="${it.goodsSpecNum}"></b>
                                <i th:if="${item.getAuditStatus()==0 }" class="layui-icon layui-icon-edit upd_goods" th:attr="d_item_id=${it.id},shopId=${item.shopId}" title="修改商品"></i> 
                                ID:<b th:text="${it.pddGoodId}"></b>
                            </p>

                        </div>
                    </td>
                    <td>
                        <p th:if="${#strings.isEmpty(item.receiver_name1)==false}">
                            <b th:text="${item.receiver_name1}"></span>&nbsp;&nbsp;<span th:text="${item.receiver_phone1}"></b>
                            <a href="javascript:;" style="color: #868686" th:attr="data-id=${item.id}" class="hand_address ">
                                <i class="layui-icon layui-icon-location"></i>
                            </a>
                        </p>
                        <b th:if="${#strings.isEmpty(item.receiver_address1)}" th:text="${item.province+ item.city +item.town}"></b>
                        <b th:text="${item.receiver_address1}"></b>
                            
                    </td>

                    <td th:text="${item.shopName}"></td>
              
                    <td >
                        <b th:if="${#strings.isEmpty(item.remark)==false}" th:text="${#strings.abbreviate(item.remark,30)}" th:title="${item.remark}" style="border-color:#aea5f8;border: solid 1px;padding:1px 5px 1px 5px;background-color: #7798f4;"></b>
                        <b th:if="${#strings.isEmpty(item.result)==false}" th:text="${#strings.abbreviate(item.result,30)}" th:title="${item.result}" style="border-color:#7072eb;border: solid 1px;padding:1px 5px 1px 5px;background-color: #8e98ee;"></b>
                
                    </td>

                    <td >
                        <b  th:text="${T(com.b2c.entity.pdd.EnumPddOrderStatus).getName(item.order_status)}"></b><br />
                        <b th:if="${item.refund_status == 1}" style="color:#e3e3e5;">无售后</b>
                        <b th:if="${item.refund_status == 2}">售后中</b>
                    </td>
                    <!--<td ></td>-->
                    <td>
                        <a th:if="${item.auditStatus == 0 && item.order_status!=4}"  class="layui-btn-xs layui-btn-primary confirm"  th:attr="order-id=${item.id}" href="javascript:;">
                            确认订单
                        </a>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="pages">
                <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
            </div>
        </div>
    </div>



    <script type="text/javascript" src="/sb/jquery.min.js"></script>
    <script type="text/javascript" src="/sb/Tips.min.js"></script>
    <script type="text/template" id="modify_address">
        <div class="T-box">
            <p><span>姓名</span><input type="text" id="userName" name="userName" /></p>
            <p><span>手机号</span><input type="text" id="mobile" name="mobile" /></p>
            <p><span>收货地址</span><input type="text" id="address" name="address"/></p>
        </div>
    </script>
    <!-- end sp-wrapper -->
    <script>
        layui.use(['laydate', 'layer','form'], function () {
            var laydate = layui.laydate;
            var layer = layui.layer;
            var form = layui.form;

            laydate.render({
                elem: '#startTime'
            });
            laydate.render({
                elem: '#endTime'
            });
            $(function () {
                $("#shopId").val('[[${shopId}]]');
                form.render('select'); //刷新select选择框渲染

                $('#allCheck').on('change', function (e) {
                    var checked = $('#allCheck').prop('checked');
                    $('.currCheck').prop('checked', checked);
                    $('#order-num').text(getNum());
                    $('#order-num_').text(getNum());
                });

                $('.currCheck').on('change', function (e) {
                    var allChecked;
                    for (var i = 0; i < $('.currCheck').length; i++) {
                        var checked = $('.currCheck').eq(i).prop('checked');
                        if (!checked) {
                            $('#allCheck').prop('checked', false);
                            $('#order-num').text(getNum());
                            $('#order-num_').text(getNum());
                        return;
                        }
                    }
                    $('#allCheck').prop('checked', true);
                    $('#order-num').text(getNum());
                    $('#order-num_').text(getNum());
                });

                function getNum() {
                    var num = 0;
                    for (var i = 0; i < $('.currCheck').length; i++) {
                        var checked = $('.currCheck').eq(i).prop('checked');
                        if (checked) {
                            num++;
                        }
                    }
                    return num;
                }


            });

            //补充收货地址
            $('.hand_address').click(function (e) {
                e.stopPropagation();
                e.preventDefault();
                var id = $(this).attr('data-id');
                Tips.confirm({
                    title: '补充收货地址',
                    content: $('#modify_address').html(),
                    define: function () {
                        var data = {
                            id: id,
                            name: $("input[name='userName']").val(),
                            mobile: $("input[name='mobile']").val(),
                            address: $("input[name='address']").val()
                        };
                        $.ajax({
                            url: "/ajax_pdd/order_hand_address",
                            type: "POST",
                            dataType: 'json',
                            contentType: 'application/json',
                            data: JSON.stringify(data),
                            success: function (res) {
                                if (res.code == 0) {
                                    Tips.alert('成功', function () {
                                        location.reload(true);
                                    });
                                } else {
                                    Tips.alert(res.msg);
                                }
                            }
                        });
                    }
                });
            });

            //确认订单
            $(".confirm").click(function () {
                    var $this = $(this);
                    confirmBtn = $this;
                    var orderId = $(this).attr("order-id");
                    //确认订单iframe层
                    layer.open({
                        type: 2,
                        title: '订单确认',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['480px', '750px'],
                        content: '/pdd/order_confirm?orderId=' + orderId  //iframe的url
                    });
                });

            //变更商品
            $(".upd_goods").click(function () {
                    var $this = $(this);
                    var orderItemId =  $this.attr("d_item_id");
                    var shopId =  $this.attr('shopId');
                    //确认订单iframe层
                    layer.open({
                        type: 2,
                        title: '修改订单商品',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['1100px', '650px'],
                        content: '/pdd/order_item_upd_goods?orderItemId=' + orderItemId +'&shopId='+shopId//iframe的url
                    });

                })//end

            //批量确认订单
            $("#confirm_batch").click(function () {
                var ids = [];
                $("input[name^='ids']").each(function (i, el) {
                    if ($(this).is(':checked'))
                        ids.push($(this).val());
                });
                console.log(ids);
                if (ids.length == 0)
                    alert("请选择订单");
                else {
                    if (confirm("你选中的订单将会确认到仓库，确定要操作吗？")) {
                        $.ajax({
                            url: "/fahuo/pdd_order_confirm_batch",
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json",
                            data: JSON.stringify({ids: ids.join()}),
                            success: function (res) {
                                alert(res.msg);
                                console.log(res);
                                if (res.code == 0) {
                                    window.location.reload();
                                } 
                            },
                            complete: function (XMLHttpRequest) {
                                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "NO_ACCESS") alert("无权限访问");
                            },
                        });
                    }
                }
            });



        });
        function confirm_order(){
            layer.msg("确认成功");
            $(confirmBtn).remove();
        }

    </script>
</div>
</body>
<html>
